﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using IBll;
using Model;

namespace Bll
{
    public partial class UserInfoBll
    {
        public UserInfo GetUserInfoByUsernamePassword(string username, string password)
        {
            //禁用此上下文的代理类功能（延迟加载），为了从MemoryCache中取缓存时，,不报"找不到以'EntityFrameworkDynamicProxies-'开头的程序集"的错误
            CurrentDalSession.CurrentDbContext.Configuration.ProxyCreationEnabled = false;
            var T_UserInfo = CurrentDalSession.CurrentDbContext.UserInfo;
            UserInfo result = null;

            var lstTemp = from A in T_UserInfo
                where (
                    A.LoginName == username
                    && A.LoginPassword == password
                    )
                select A;
            var obj = lstTemp.FirstOrDefault();
            if (obj != null)
            {
                result = (UserInfo) obj;
            }
            //返回前，开启代理类功能
            CurrentDalSession.CurrentDbContext.Configuration.ProxyCreationEnabled = true;

            return result;
        }
    }
}
